package com.xtoad.ecms.baseinfo.model;

import com.xtoad.ecms.common.web.base.BaseModel;
import org.hibernate.annotations.Table;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 * 组织实体类
 *
 * @author xtoad
 * @date 2021/02/14
 */
@Entity
@Table(appliesTo = "organization", comment = "组织表")
public class Organization extends BaseModel {

    /**
     * 组织编码
     */
    @Column(nullable = false, unique = true, columnDefinition = "varchar(25) comment '组织编码'")
    private String code;

    /**
     * 组织名称
     */
    @Column(nullable = false, unique = false, columnDefinition = "varchar(50) comment '组织名称'")
    private String name;

    /**
     * 父组织
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(nullable = true, columnDefinition = "comment '父组织'")
    private Organization parent;


    /**
     * 获取 组织编码
     */
    public String getCode() {
        return this.code;
    }

    /**
     * 设置 组织编码
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * 获取 组织名称
     */
    public String getName() {
        return this.name;
    }

    /**
     * 设置 组织名称
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取 父组织
     */
    public Organization getParent() {
        return this.parent;
    }

    /**
     * 设置 父组织
     */
    public void setParent(Organization parent) {
        this.parent = parent;
    }

    @Override
    public String toString() {
        return "Organization{" +
                "code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", parent=" + parent +
                "} " + super.toString();
    }
}
